local cmp = require("cmp")
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.event:on(
  'confirm_done',
  cmp_autopairs.on_confirm_done()
)
cmp.setup({
    -- 指定 snippet 引擎
    snippet = {
        expand = function(args)
            -- For `vsnip` users.
            vim.fn["vsnip#anonymous"](args.body)

            -- For `luasnip` users.
            -- require('luasnip').lsp_expand(args.body)

            -- For `ultisnips` users.
            -- vim.fn["UltiSnips#Anon"](args.body)

            -- For `snippy` users.
            -- require'snippy'.expand_snippet(args.body)
        end,
    },
    -- 补全源
    sources = cmp.config.sources({
        { name = "nvim_lsp" },
        -- For vsnip users.
        { name = "vsnip" },

        -- For luasnip users.
        -- { name = 'luasnip' },

        --For ultisnips users.
        -- { name = 'ultisnips' },

        -- -- For snippy users.
        -- { name = 'snippy' },
    }, { { name = "buffer" }, { name = "path" } }),

    -- 快捷键设置
    mapping = require("keybindings").cmp(cmp),
    formatting = require('lsp.ui').formatting
})

-- / 查找模式使用 buffer 源
cmp.setup.cmdline("/", {
    mapping = cmp.mapping.preset.cmdline(),
    sources = {
        { name = "buffer" },
    },
})

-- : 命令行模式中使用 path 和 cmdline 源.
local cmd_default_maps = cmp.mapping.preset.cmdline()
-- 设置无效暂时不用
--local cmd_new_maps = {
    --["<C-N>"] = cmp.config.disable,
    --["<C-P>"] = cmp.config.disable
--}
--local cmd_maps = vim.tbl_deep_extend("force", cmd_default_maps, cmd_new_maps)
--for k, v in pairs(cmd_maps) do
    --print(k, v)
--end
cmp.setup.cmdline(":", {
    completion = { autocomplete = false },
    mapping = cmd_default_maps,
    sources = cmp.config.sources({
        { name = "path" },
    }, {
        { name = "cmdline" },
    }),
})
